<?php

class Migration extends CI_Controller {

	function __construct() {
		parent::__construct();
		$this -> load -> library('migration');
	}

	function index() {

		if (!$this -> migration -> current()) {
			show_error($this -> migration -> error_string());
		} else {
			echo ' Migration ' . $this -> migration -> version() . ' Criado ';
		}
	}

	function install() {
		$this -> config -> load('migration');
		$has_migration = $this -> config -> item('migration_version');

		if ($has_migration) {

			for ($i = 1; $i <= $has_migration; $i += 1) {
				$this -> version($i);
			}
		}
		
		echo 'FINALIZADO (VERSION DATABASE ) '.$has_migration.' .';

	}

	private function version($version) {
		$migration = $this -> migration -> version($version);
		unset($this -> db -> data_cache['table_names']);
		if (!$migration) {
			echo $this -> migration -> error_string().PHP_EOL;
		} else {
			return true;
		}
	}

}
